package org.phalanx.client.menus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

import org.phalanx.client.UI.DialogManager;
import org.phalanx.client.mapeditor.PhalanxMapEditorPanel;
import org.phalanx.client.mapeditor.dialogs.DefaultTileSetDialog;
import org.phalanx.client.mapeditor.dialogs.PhalanxMapInfoDialog;
import org.phalanx.client.mapeditor.dialogs.PhalanxMapResizeDialog;
import org.phalanx.client.mapeditor.dialogs.PhalanxMapTileSetChooserDialog;

public class DesignMenuAction implements ActionListener {
	private PhalanxMapEditorPanel masterPanel;
	
	public DesignMenuAction(PhalanxMapEditorPanel parentPanel){
		this.masterPanel = parentPanel;
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() instanceof JMenuItem){
			JMenuItem menuSelected = (JMenuItem)e.getSource();
			
			if (menuSelected.getName().equals("setdefaulttile")){
				DialogManager d = DialogManager.getInstance();
				
				if (d.getDialog(DefaultTileSetDialog.NAME) == null){
					d.setDialog(DefaultTileSetDialog.NAME, 
							new DefaultTileSetDialog(masterPanel));
				}
				
				d.getDialog(DefaultTileSetDialog.NAME).setVisible(true);
			}
			else if (menuSelected.getName().equals("mapproperties")) {
				DialogManager d = DialogManager.getInstance();
				
				if (d.getDialog(PhalanxMapInfoDialog.NAME) == null) {
					d.setDialog(PhalanxMapInfoDialog.NAME,
							new PhalanxMapInfoDialog(masterPanel));
				}
				
				d.getDialog(PhalanxMapInfoDialog.NAME).setVisible(true);
			}
			else if (menuSelected.getName().equals("changetileset")) {
				DialogManager d = DialogManager.getInstance();
				
				if (d.getDialog(PhalanxMapTileSetChooserDialog.NAME) == null) {
					d.setDialog(PhalanxMapTileSetChooserDialog.NAME,
							new PhalanxMapTileSetChooserDialog(masterPanel));
				}
				
				d.getDialog(PhalanxMapTileSetChooserDialog.NAME).setVisible(true);
			}
			
			else if (menuSelected.getName().equals("resizemap")) {
				DialogManager d = DialogManager.getInstance();
				
				if (d.getDialog(PhalanxMapResizeDialog.NAME) == null) {
					d.setDialog(PhalanxMapResizeDialog.NAME,
							new PhalanxMapResizeDialog(masterPanel));
				}
				
				d.getDialog(PhalanxMapResizeDialog.NAME).setVisible(true);
			}
			
		}
	}

}
